//
//  TNButton.m
//  跑跑快销
//
//  Created by ylife on 14-4-29.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "TNButton.h"

@implementation TNButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.contentMode = UIViewContentModeCenter;
        [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
        [self setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
    }
    return self;
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    contentRect.origin.y += contentRect.origin.y + self.frame.size.height / 3;
//    contentRect.origin.x += 12;
//    contentRect.size.width -= 0;
    return contentRect;
}
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
//    contentRect.size.width -= 4;
    contentRect.size.height -= self.frame.size.height / 3 ;
    return contentRect;
}

//添加圆角矩形按钮
+ (TNButton *)addButtonWithTitle:(NSString *)title andButtonImageName:(NSString *)imageName andFrame:(CGRect)frame
{
    
    TNButton *button = [[TNButton alloc]initWithFrame:frame];
    [button.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [button.titleLabel setFont:[UIFont systemFontOfSize:11]];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    button.imageView.layer.masksToBounds = YES;
    button.imageView.layer.cornerRadius =frame.size.width / 4;
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
//    [view addSubview:button];
    return button;
}

+ (TNButton *)addRoundButtonWithFrame:(CGRect)frame
{
    TNButton *button = [[TNButton alloc]initWithFrame:frame];
    [button.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [button.titleLabel setFont:[UIFont systemFontOfSize:11]];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.imageView.layer.masksToBounds = YES;
    button.imageView.layer.cornerRadius = frame.size.height / 3;
//    [view addSubview:button];
    return button;
}

//添加圆形按钮
+ (TNButton *)addRoundButtonWithTitle:(NSString *)title andButtonImageName:(NSString *)imageName andFrame:(CGRect)frame
{
    TNButton *button = [[TNButton alloc]initWithFrame:frame];
    [button.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [button.titleLabel setFont:[UIFont systemFontOfSize:11]];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    button.imageView.layer.masksToBounds = YES;
    button.imageView.layer.cornerRadius = frame.size.height / 3;
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
//    [view addSubview:button];
    return button;
}


@end
